<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns="http://www.w3.org/1999/xhtml">
    

        <h:form id="form">
        
            <p:dataTable id="tabVerde" var="tVerde" value="#{tarifaFace.listaVerde}" 
                         selectionMode="single" emptyMessage="Nenhum registro encontrado."
                         height="50" widgetVar="tarVerde">

                <f:facet name="header" >Tarifa Horo-Sazonal Verde
<!--                    <p:outputPanel>
                        <h:outputText value="Search all fields:" />
                        <h:inputText id="globalFilter" onkeyup="tarVerde.filter()" />
                    </p:outputPanel>-->
                </f:facet>

                <p:column sortBy="#{tVerde.id}">
                    <f:facet name="header"><h:outputText value="Id"/></f:facet>
                    <h:outputText value="#{tVerde.id}"/>
                </p:column>
                <p:column sortBy="#{tVerde.tarifa.conce.abrev}" filterBy="#{tVerde.tarifa.conce.abrev}" filterMatchMode="contains">
                    <f:facet name="header"><h:outputText value="Concessionária"/></f:facet>
                    <h:outputText value="#{tVerde.tarifa.conce.abrev}"/>
                </p:column>
                
                <p:column sortBy="#{tVerde.inicio}">
                    <f:facet name="header"><h:outputText value="Vig. Início"/></f:facet>
                    <h:outputText value="#{tVerde.inicio}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                </p:column>
                
                <p:column >
                    <f:facet name="header"><h:outputText value="Demanda"/></f:facet>
                    <h:outputText value="#{tVerde.KW}">
                        <f:convertNumber minFractionDigits="2" locale="pt_BR"/>
                    </h:outputText>
                </p:column>

                <p:column >
                    <f:facet name="header"><h:outputText value="kWh Ponta Seca"/></f:facet>
                    <h:outputText value="#{tVerde.KWhPS}">
                        <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                    </h:outputText>
                </p:column>
                
                <p:column >
                    <f:facet name="header"><h:outputText value="kWh Ponta Úmida"/></f:facet>
                    <h:outputText value="#{tVerde.KWhPU}">
                        <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                    </h:outputText>
                </p:column>
                
                <p:column >
                    <f:facet name="header"><h:outputText value="kWh Fora Ponta Seca"/></f:facet>
                    <h:outputText value="#{tVerde.KWhFPS}">
                        <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                    </h:outputText>
                </p:column>
                
                <p:column >
                    <f:facet name="header"><h:outputText value="kWh Fora Ponta Úmida"/></f:facet>
                    <h:outputText value="#{tVerde.KWhFPU}">
                        <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                    </h:outputText>
                </p:column>
                
                
                
                <p:column>
                    <f:facet name="header">Ações</f:facet>
                    <p:commandButton image="ui-icon-pencil" update=":form:painel"
                                     oncomplete="conceDialog.show()" title="Editar" >
                        <f:setPropertyActionListener value="#{tVerde}" target="#{tarifaFace.selectedBean}" />
                        <f:setPropertyActionListener target="#{tarifaFace.tarifaNome}" value="verde" />
                    </p:commandButton>

                    <p:commandButton image="ui-icon-trash" update=":form:painel"
                                     title="Excluir" oncomplete="confirmation.show()" >
                        <f:setPropertyActionListener value="#{tVerde}" target="#{tarifaFace.selectedBean}" />
                    </p:commandButton>
                    
                </p:column>
                <f:facet name="footer" >
                    <p:commandButton image="ui-icon-disk" update=":form:painel"
                                     title="Novo" value="Novo" oncomplete="conceDialog.show()"
                                     action="#{tarifaFace.doCreate}">
                        <f:setPropertyActionListener target="#{tarifaFace.tarifaNome}" value="verde" />
                    </p:commandButton>
                </f:facet>
            </p:dataTable>

            <p:dialog widgetVar="conceDialog" width="600" resizable="true"
                      id="conceDlg" header="Cadastro de Tarifa Horo-Sazonal Verde" showEffect="explode"
                      hideEffect="slide" modal="true">
                <p:outputPanel id="painel" rendered="true" >
                    <script type="text/javascript">
                        (function($){
                            $(function(){
                                $('input:text').setMask();
                            });
                        })(jQuery);
                    </script>
                    <h:panelGrid columns="2"  >
                        <h:outputLabel value="Concessionária:"/>
                        <h:selectOneMenu  value="#{tarifaFace.selectedBean.tarifa}" converter="tarifaConverter" 
                                          rendered="true" >
                            <f:selectItems value="#{tarifaFace.listaTarifa}" var="cbVerde"
                                           itemLabel="#{cbVerde.conce.abrev}" itemValue="#{cbVerde}" >
                            </f:selectItems>
                            
                        </h:selectOneMenu>
                        
                        <h:outputLabel value="Início da Vigência:"/>
                        <p:calendar id="ical" value="#{tarifaFace.selectedBean.inicio}" pattern="dd/MM/yyyy" rendered="true" />

                        <h:outputLabel value="Demanda:"/>
                        <p:inputText id="idm" value="#{tarifaFace.selectedBean.KW}" rendered="true" alt="decimal" >
                            <f:convertNumber minFractionDigits="2" locale="pt_BR"/>
                        </p:inputText>
                        
                        <h:outputLabel value="Consumo Ponta Seca:"/>
                        <p:inputText id="ips" value="#{tarifaFace.selectedBean.KWhPS}" rendered="true" alt="decimal6" >
                            <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                        </p:inputText>
                        <h:outputLabel value="Consumo Ponta Úmida:"/>
                        <p:inputText id="ipu" value="#{tarifaFace.selectedBean.KWhPU}" rendered="true" alt="decimal6">
                            <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                        </p:inputText>
                        <h:outputLabel value="Consumo Fora Ponta Seca:"/>
                        <p:inputText id="ifps" value="#{tarifaFace.selectedBean.KWhFPS}" rendered="true" alt="decimal6">
                            <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                        </p:inputText>
                        <h:outputLabel value="Consumo Ponta Seca:"/>
                        <p:inputText id="ifpu" value="#{tarifaFace.selectedBean.KWhFPU}" rendered="true" alt="decimal6">
                            <f:convertNumber minFractionDigits="6" locale="pt_BR"/>
                        </p:inputText>
                        
                        <p:commandButton value="Salvar" action="#{tarifaFace.doSave()}"
                                         oncomplete="conceDialog.hide()" update="tabVerde">

                        </p:commandButton>
                        <p:commandButton value="Cancelar" oncomplete="conceDialog.hide()" 
                                         action="#{tarifaFace.resetIsNew}">

                        </p:commandButton>
                    </h:panelGrid>

                </p:outputPanel>
            </p:dialog>

            <p:confirmDialog message="Você deseja realmente exluir este registro?" width="200"
                             showEffect="explode" hideEffect="explode"
                             header="Confirmação" severity="alert" widgetVar="confirmation" modal="true" >

                <p:commandButton value="Sim" update="tabVerde" action="#{tarifaFace.doRemove}"
                                 oncomplete="confirmation.hide()"/>
                <p:commandButton value="Não" onclick="confirmation.hide()" type="button" />

            </p:confirmDialog>
            <br></br>
        </h:form>

</ui:composition>